/*
 * Copyright 2013 JROSE
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jrose.entity.constant;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * Gender definition.
 *
 * @author Xiaohai Zhang
 * @since 2013-08-29 21:07
 */
public enum Gender {
    Male("男", new GenderDisplayName(Race.monster, "公")),
    Female("女", new GenderDisplayName(Race.monster, "母")),
    Asexuality("无性");

    @Getter private final String name;
    private final Map<Race, String> displayNames;

    private Gender(String name, GenderDisplayName... genderDisplayNames) {
        this.name = name;
        this.displayNames = new HashMap<>();
        if (genderDisplayNames != null && genderDisplayNames.length > 0) {
            for (GenderDisplayName displayName : genderDisplayNames) {
                this.displayNames.put(displayName.getRace(), displayName.getName());
            }
        }
    }

    public String displayName(Race race) {
        if (race == null || !displayNames.containsKey(race)) {
            return name;
        }
        return displayNames.get(race);
    }

    private static class GenderDisplayName {
        private final Race race;
        private final String name;

        private GenderDisplayName(Race race, String name) {
            this.race = race;
            this.name = name;
        }

        public Race getRace() {
            return race;
        }

        public String getName() {
            return name;
        }
    }
}
